package think.in.java.concurrency.PractiseOneMoreTime;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * Experiment with different sleep times in Daemons.java to see what happens.
 *
 */
public class Exec7And8ForSleepTime {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new Daemons(20));
        thread.setDaemon(true);
        thread.start();
        TimeUnit.MILLISECONDS.sleep(100);
    }

}

class Daemons implements  Runnable{
    private int threads =1;
    public Daemons(int threads){
        this.threads= threads;
    }

    @Override
    public void run() {
        List<Thread> threadList = new ArrayList<Thread>();
        for(int i=0; i < threads ; i++){
            Thread thread = new Thread();
            thread.start();
            threadList.add(thread);
            Thread.yield();
        }
        for(Thread thread: threadList){
            System.out.println(thread.getName() + " :isDaemon: " + thread.isDaemon());
        }
        for(;;){
            Thread.yield();
        }

    }
}

class DaemonSpan implements  Runnable{

    @Override
    public void run() {
        for(;;){
            Thread.yield();
        }
    }
}
